function UseBagItem(itemName)
	if GetItemCount(itemName) > 0 
	and IsUsableItem(itemName) == 1
	and GetItemCooldown(itemName) == 0
	then
		UseItemByName(itemName)
	end
end

function UseTrinkets()
	local TrinketA={GetInventoryItemCooldown("Player", 13)}
	local TrinketB={GetInventoryItemCooldown("Player", 14)}
	if TrinketA[3]==1 and TrinketA[1]==0 then UseInventoryItem(13) return end
	if SpellIsTargeting() == 1 and Target and Target:Exists() and not Target:IsDead() then CastAtLocation(Target:GetLocation()) end;
	if TrinketB[3]==1 and TrinketB[1]==0 then UseInventoryItem(14) return end
	if SpellIsTargeting() == 1 and Target and Target:Exists() and not Target:IsDead() then CastAtLocation(Target:GetLocation()) end;
end

function PrintToChat(message)
	local vccR = "|cff00ff00ccR /> "
	-- Prevent duplications
	if vLastccRMessage ~= nil
	and message == vLastccRMessage
	then
		return
	end
	vLastccRMessage = message
	DEFAULT_CHAT_FRAME:AddMessage(vccR .. string.join(" ", tostringall(message)), 0.41, 0.8, 0.94)
end

function ccrValidTarget(unit)
	if unit == nil then unit = "target" end;
	if UnitExists(unit) == 1
	and UnitCanAttack("Player", unit) == 1
	and UnitIsDead(unit) ~= 1
	and Target
	and Target:Exists()
	and not Target:IsDead()
	then
		return true
	else
		return false
	end
end

function SpellIDToName(spellid)
	local vSpell = {GetSpellInfo(spellid)}
	return vSpell[1]
end

function SpellNameToID(spellname)
	local vSpell = {GetSpellInfo(spellname)}
	return vSpell[2]
end

function ccrDistance(source, target)
	vSource = GetObjectFromUnitID(source)
	vTarget = GetObjectFromUnitID(target)
	if vSource
	and vTarget
	and vSource:Exists()
	and vTarget:Exists()
	then
		return vSource:GetDistance(vTarget)
	end
end